#include <bits/stdc++.h>
using namespace std;

const int inf = 0x7fffffff;

inline void File() {
#ifdef DEBUG
    freopen("in.txt", "r", stdin);
#else 
    freopen("roundtable.in", "r", stdin);
    freopen("roundtable.out", "w", stdout);
#endif
}
 
inline int get_num() {
    int k = 0;
    char c = getchar();
    for(; !isdigit(c); c = getchar());
    for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k;
}

int cnt, head[400];

class edge {
public:
    int fr, to, v, ne, v_bak;//v是容量
    edge(){to = 0,v = 0, ne = 0, v_bak = 0;}
    edge(int fr_, int to_, int v_,int ne_) {
        fr = fr_, to = to_, v = v_, ne = ne_;
        v_bak = v;
    }
}e[300000];

inline void addedge(int fr, int to, int v) {
    e[++cnt] = edge(fr, to, v, head[fr]), head[fr] = cnt;
    e[++cnt] = edge(to, fr, 0, head[to]), head[to] = cnt;
}

int s, t,  dis[400], zz[300], dw[300] , n, m, ans;
bool vis[400];

inline bool bfs() {
    memset(dis, 0, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    dis[s] = 0;
    vis[s] = 1;
    queue <int> q;
    q.push(s);
    while(!q.empty()) {
        int x = q.front();
        if(x == t)return true; 
        q.pop();
        for(int i = head[x]; i; i = e[i].ne) {
            int y = e[i].to;
            if(!e[i].v || vis[y])continue;
            vis[y] = 1;
            dis[y] = i;
            q.push(y);
        }
    }
    return dis[t];
}

bool end;
int st[400], top;

inline int get_flow() {
	int now = dis[t];
	int minflow = inf;
	while(now) {
		minflow = min(minflow, e[now].v);
		now = dis[e[now].fr];
	}
	now = dis[t];
	while(now) {
		e[now].v -= minflow;
		(now & 1) ? e[now + 1].v += minflow : e[now - 1].v += minflow; 
		now = dis[e[now].fr];
	}
	return minflow;
}

//int dfs(int x, int tmp) {
//    if(x == t) {
//        return tmp;
//    }
//    for(int i = head[x]; i; i = e[i].ne) {
//        int y = e[i].to;
//        if(dis[y] == dis[x] + 1 && e[i].v) {
//            int a = dfs(y, min(tmp, e[i].v));
//            if(a) {
//            	e[i].v -= a;
//            	if(i & 1) e[i + 1].v += a;
//            	else e[i - 1].v += a;
//            	return a;
//			}
//        }
//    }
//    return 0;
//}


int main() {
	freopen("roundtable.in", "r", stdin);
	freopen("roundtable.out", "w", stdout);
	int tot = 0;
    n = get_num();
    m = get_num();
    s = 0;
    t = n + m + 1;
    for(int i = 1;i <= n; i++) {
        dw[i] =  get_num();
        tot += dw[i];
    }
    for(int i = 1; i <= m; i++) {
        zz[i] = get_num();
    }
    for(int i = 1; i <= n; i++) {
        addedge(s, i, dw[i]);
    }
    for(int i = 1 ;i <= n; i++) {
        for(int j = n + 1; j <= n + m; j++) {
            addedge(i, j, 1);
        }
    }
    for(int i = 1; i <= m;i++) {
        addedge(n + i, t, zz[i]);
    }    
    
    while(bfs()) {
        ans += get_flow();
    }
	if(ans != tot) {
		printf("0");
		return 0;
	}
	else printf("1\n");
	for(int i = 1; i <= n; i++) {
		for(int j = head[i]; j; j = e[j].ne) {
			if(e[j].v) continue;
			printf("%d ", e[j].to - n);
		}
		printf("\n");
	}

}
